<html>
<head><meta charset="utf-8"><title>get llvm to dump missed vectorization · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html">get llvm to dump missed vectorization</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="247511433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247511433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247511433">(Jul 28 2021 at 20:15)</a>:</h4>
<p>So, clang seems to have a way to log when it missed some vectorizations on loops: <a href="https://llvm.org/docs/Vectorizers.html#id6">https://llvm.org/docs/Vectorizers.html#id6</a></p>
<p>Does anyone know if llvm has a generic version of this? it seems like this is a clang-specific thing but im wondering if its just a thin wrapper over some LLVM thing that we ideally could run ourselves and have a way to identify why llvm missed some vectorizations, which would be very helpful for a lot of projects.</p>



<a name="247512634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247512634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247512634">(Jul 28 2021 at 20:25)</a>:</h4>
<p>actually remarks seem to be an llvm thing, not a clang specific thing <a href="https://llvm.org/docs/Remarks.html">https://llvm.org/docs/Remarks.html</a></p>



<a name="247515604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247515604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247515604">(Jul 28 2021 at 20:51)</a>:</h4>
<p>You can use <code>-Cllvm-args</code> to pass arbitrary arguments to LLVM. They don't always exactly match clang though.</p>



<a name="247517914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247517914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247517914">(Jul 28 2021 at 21:09)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> yeah it seems that the remark flags are the same for llvm/clang, although i expect it would dump an absolute ton of remarks, although it can probably easily be filtered with a script based on the origin of the remark</p>



<a name="247518029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247518029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247518029">(Jul 28 2021 at 21:10)</a>:</h4>
<p>ill explore this more, if this works well it should be really helpful to have as an unstable rustc flag or something of the sort</p>



<a name="247519470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247519470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247519470">(Jul 28 2021 at 21:23)</a>:</h4>
<p>ooh its actually dumping somewhat useful info:</p>
<div class="codehilite"><pre><span></span><code>remark: /rustc/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5\library\core\src\iter\adapters\zip.rs:228:0: loop not vectorized
</code></pre></div>
<p>this is with pass-remarks-missed, then with analysis:</p>
<div class="codehilite"><pre><span></span><code>remark: /rustc/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5\library\core\src\iter\adapters\zip.rs:228:0: loop not vectorized: loop control flow is not understood by vectorizer
remark: /rustc/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5\library\alloc\src\raw_vec.rs:337:0: loop not vectorized: loop contains a switch statement
remark: /rustc/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5\library\alloc\src\vec\mod.rs:1667:0: loop not vectorized: value that could not be identified as reduction is used outside the loop
remark: /rustc/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5\library\core\src\iter\adapters\zip.rs:228:0: loop not vectorized: could not determine number of loop iterations
</code></pre></div>



<a name="247519505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247519505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247519505">(Jul 28 2021 at 21:23)</a>:</h4>
<p>this being the function: </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">u8</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">new</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Vec</span>::<span class="n">with_capacity</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">len</span><span class="p">());</span><span class="w"></span>

<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">a</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">zip</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">iter</span><span class="p">())</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">new</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">b</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="n">new</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="247519588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247519588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247519588">(Jul 28 2021 at 21:24)</a>:</h4>
<p>although the info is kind of in the wrong place because the iterator calls arent inlined</p>



<a name="247520209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520209">(Jul 28 2021 at 21:31)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">u8</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">a</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">zip</span><span class="p">(</span><span class="n">b</span><span class="p">).</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="o">|</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">b</span><span class="p">).</span><span class="n">collect</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>shorter, vectorizes :D</p>
<p><a href="https://rust.godbolt.org/z/YG1jT7vjr">https://rust.godbolt.org/z/YG1jT7vjr</a></p>



<a name="247520236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520236">(Jul 28 2021 at 21:31)</a>:</h4>
<p>yeah i realize what the issue here is, i just wanted to see if llvm could tell me what it is</p>



<a name="247520330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520330">(Jul 28 2021 at 21:32)</a>:</h4>
<p>sorry, couldn't resist the godbolt golfing</p>



<a name="247520331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520331">(Jul 28 2021 at 21:32)</a>:</h4>
<p>lol</p>



<a name="247520396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520396">(Jul 28 2021 at 21:33)</a>:</h4>
<p>for some reason i cant pass <code>-pass-remarks-output</code> to rustc</p>



<a name="247520606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520606">(Jul 28 2021 at 21:36)</a>:</h4>
<p>I didn't know about remarks this will be useful for optimization work <span aria-label="ok" class="emoji emoji-1f44c" role="img" title="ok">:ok:</span></p>



<a name="247520622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520622">(Jul 28 2021 at 21:36)</a>:</h4>
<p>i think the last remark is the useful one, the rest are kind of meh</p>



<a name="247520645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520645">(Jul 28 2021 at 21:37)</a>:</h4>
<p>because it cant figure out if a and b are the same length</p>



<a name="247520719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520719">(Jul 28 2021 at 21:38)</a>:</h4>
<p>im guessing vectorization is run before inlining, which is why this is pointing to external functions</p>



<a name="247520809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520809">(Jul 28 2021 at 21:38)</a>:</h4>
<p>I'm pretty sure it happens after inlining. some vectorization potential is only unlocked when the caller context is known</p>



<a name="247520845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520845">(Jul 28 2021 at 21:39)</a>:</h4>
<p>then it might be preserving info about the original function</p>



<a name="247520917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520917">(Jul 28 2021 at 21:40)</a>:</h4>
<p>yeah, debuginfo does that too</p>



<a name="247520961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247520961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247520961">(Jul 28 2021 at 21:40)</a>:</h4>
<p>yeah although this makes it a little bit less user friendly</p>



<a name="247521303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247521303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247521303">(Jul 28 2021 at 21:45)</a>:</h4>
<p><code>-C remark=all</code> prints LLVM optimization remarks.</p>



<a name="247521463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247521463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247521463">(Jul 28 2021 at 21:47)</a>:</h4>
<p>it prints nothing for some reason</p>



<a name="247521528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247521528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247521528">(Jul 28 2021 at 21:48)</a>:</h4>
<p>using <code>RUSTFLAGS="-C remark=all"</code></p>



<a name="247521776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247521776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247521776">(Jul 28 2021 at 21:51)</a>:</h4>
<p>ah it prints something with cargo rustc but not cargo build, odd</p>



<a name="247522002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247522002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247522002">(Jul 28 2021 at 21:54)</a>:</h4>
<p>doesnt print anything related to vectorization however</p>



<a name="247526781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247526781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247526781">(Jul 28 2021 at 22:50)</a>:</h4>
<p>I also researched the non-vectorized version more, and it turns out llvm is really bad at vectorizing anything with a vector push. Im guessing llvm has no idea how to propagate the data flow info through the loop and guess that theres no way the vec can realloc</p>



<a name="247526836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247526836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247526836">(Jul 28 2021 at 22:50)</a>:</h4>
<p>this vectorizes which proves it:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo_with_unsafe_length_assertion</span><span class="p">(</span><span class="n">a</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">u8</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">new</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Vec</span>::<span class="n">with_capacity</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">len</span><span class="p">().</span><span class="n">max</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">len</span><span class="p">()));</span><span class="w"></span>

<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">a</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">zip</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">iter</span><span class="p">())</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="fm">debug_assert!</span><span class="p">(</span><span class="n">new</span><span class="p">.</span><span class="n">capacity</span><span class="p">()</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">new</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="n">new</span><span class="p">.</span><span class="n">capacity</span><span class="p">()</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">new</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">std</span>::<span class="n">hint</span>::<span class="n">unreachable_unchecked</span><span class="p">();</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>

<span class="w">        </span><span class="n">new</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">b</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="n">new</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="247526894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247526894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247526894">(Jul 28 2021 at 22:51)</a>:</h4>
<p>which further proves that iterators are so much better than "manual" loops like this <span aria-label="stuck out tongue" class="emoji emoji-1f61b" role="img" title="stuck out tongue">:stuck_out_tongue:</span></p>



<a name="247527615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/get%20llvm%20to%20dump%20missed%20vectorization/near/247527615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/get.20llvm.20to.20dump.20missed.20vectorization.html#247527615">(Jul 28 2021 at 22:59)</a>:</h4>
<p>to be fair, significant amounts of unsafe code in the standard library are dedicated to optimize the collect version of this case.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>